package com.ljq.software_springboot.softwareprogram.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ljq.software_springboot.softwareprogram.entity.Account;
import com.ljq.software_springboot.softwareprogram.entity.Chatgroup;
import com.ljq.software_springboot.softwareprogram.mapper.ChatgroupMapper;
import com.ljq.software_springboot.softwareprogram.service.IChatgroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-29
 */
@Service
public class ChatgroupServiceImpl extends ServiceImpl<ChatgroupMapper, Chatgroup> implements IChatgroupService {
    @Autowired
    private ChatgroupMapper chatgroupMapper;

    public List<Chatgroup> findAll(int id) {
        LambdaQueryWrapper<Chatgroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Chatgroup::getCreatorId, id);
        return chatgroupMapper.selectList(queryWrapper);
    }

    public Integer findId(String username) {
        LambdaQueryWrapper<Chatgroup> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Chatgroup::getName, username);
        Chatgroup existingAccount = chatgroupMapper.selectOne(queryWrapper);
        return existingAccount.getId();
    }

    public List<Chatgroup> findgroup(int id) {
        return chatgroupMapper.findGroups(id);
    }
}
